<?php
class Z1ketnapdvsController extends AppController {

	var $name = 'Z1ketnapdvs';
    var $uses=array('Ketnapdv','Qdketnap','Z1ketnapdv');

	function index($cd_id) {
		$this->Z1ketnapdv->recursive = -1;
        $this->paginate=array(
            'conditions'=>array('chidoansv_id'=>$cd_id),
            'recursive'=>-1
        );
		$this->set('z1ketnapdvs', $this->paginate('Z1ketnapdv'));
        $this->set(compact('cd_id'));
	}
    function luu($chidoan){
        if(!empty($this->data)){
            $this->Ketnapdv->create();
            $record['Ketnapdv'] ['chidoan_id']=$chidoan;
            
         //   $record['Ketnapdv'] ['sinhvien_id']=$this->data['Z1ketnapdv'] ['sinhvien_id'];
            $this->Ketnapdv->save($record);
            $record ['Qdketnap']['ketnapdv_id']=$this->Ketnapdv->id;
            foreach($this->data['Z1ketnap']['checked'] as $value){
                $record ['Qdketnap'] ['sinhvien_id']=$value;
                $this->Qdketnap->create();
                $this->Qdketnap->save($record);
            
            }
        }
    }

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid z1ketnapdv', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('z1ketnapdv', $this->Z1ketnapdv->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Z1ketnapdv->create();
			if ($this->Z1ketnapdv->save($this->data)) {
				$this->Session->setFlash(__('The z1ketnapdv has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The z1ketnapdv could not be saved. Please, try again.', true));
			}
		}
		$tongiaos = $this->Z1ketnapdv->Tongiao->find('list');
		$phuongxas = $this->Z1ketnapdv->Phuongxa->find('list');
		$dantocs = $this->Z1ketnapdv->Dantoc->find('list');
		$this->set(compact('tongiaos', 'phuongxas', 'dantocs'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid z1ketnapdv', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Z1ketnapdv->save($this->data)) {
				$this->Session->setFlash(__('The z1ketnapdv has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The z1ketnapdv could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Z1ketnapdv->read(null, $id);
		}
		$tongiaos = $this->Z1ketnapdv->Tongiao->find('list');
		$phuongxas = $this->Z1ketnapdv->Phuongxa->find('list');
		$dantocs = $this->Z1ketnapdv->Dantoc->find('list');
		$this->set(compact('tongiaos', 'phuongxas', 'dantocs'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for z1ketnapdv', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Z1ketnapdv->delete($id)) {
			$this->Session->setFlash(__('Z1ketnapdv deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Z1ketnapdv was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
